//
//  MineOrderCell.m
//  PaiLeXiongProject
//
//  Created by 小獾科技 on 2017/8/28.
//  Copyright © 2017年 小獾科技. All rights reserved.
//

#import "MineOrderCell.h"
#import "MineCollectionViewCell.h"
#import "MineAllOrderViewController.h"

@interface MineOrderCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UILabel *myOrderLabel;

@property (nonatomic, strong) NSMutableArray *datasource;
@end

@implementation MineOrderCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
               
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = ColorFrom16(0xeef4f7);
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 10, GWIDTH, 152 - 20)];
        view.backgroundColor = ColorWhite;
        [self addSubview:view];
        
        _myOrderLabel = [UILabel new];
        _myOrderLabel.text = @"我的订单";
        _myOrderLabel.textColor = ColorFrom16(0x333333);
        _myOrderLabel.font = PFMFONT(20);
        [view addSubview:_myOrderLabel];
        [_myOrderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view).offset(10);
            make.centerX.equalTo(view.mas_centerX);
            make.width.equalTo(@90);
            make.height.equalTo(@25);
        }];
        
        UIView *line = [UIView new];
        line.backgroundColor = ColorFrom16(0xeef4f7);
        [view addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_myOrderLabel.mas_bottom).offset(9);
            make.left.and.right.equalTo(view);
            make.height.equalTo(@1);
        }];
        
        UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
        layout.minimumLineSpacing = 0;
        layout.minimumInteritemSpacing = 0;
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 55, GWIDTH, 77) collectionViewLayout:layout];
        _collectionView.backgroundColor = ColorWhite;
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.scrollEnabled = NO;
        [_collectionView registerClass:[MineCollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
        [view addSubview:_collectionView];

        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(actionaa) name:@"tabbarselect" object:nil];
        
//        _datasource = [NSMutableArray arrayWithCapacity:0];
//        [NetWork sendGetRequestURL:@"https://clubbear.clubbear.cn/common/getOrderCount" parameters:nil completionBlockWithSuccess:^(NSDictionary *resultDict) {
//                    NSLog(@"数量 %@", resultDict);
//            numberModel *model = [GW_Tool getObjFromDictionary:resultDict[@"data"] byClassName:@"numberModel"];
//            [self.datasource addObject:model];
//            [_collectionView reloadData];
//        } andFailure:^(NSError *error, NSString *errorMsg) {
//            NSLog(@"%@", error);
//        }];
        
    }
    return self;
}

- (void)actionaa
{
    //    self.tabBarController.selectedIndex = 3;
    //    [[NSNotificationCenter defaultCenter] postNotificationName:@"push" object:nil];//我的订单全部
//    self.tabBarController.selectedIndex = 3;
    MineAllOrderViewController *all = [MineAllOrderViewController new];
    //    all.status = @"5";
    [all startNetwork:@"1"];
    [self.viewController.navigationController pushViewController:[MineAllOrderViewController new] animated:YES];
}


- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 5;
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    return CGSizeMake(GWIDTH / 5, 77);
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    MineCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
    numberModel *model = self.array[0];
//    model = self.model;
    switch (indexPath.row) {
        case 0:
            cell.functionLabel.text = @"待付款";
            cell.imgView.image = IMAGE(@"mine_paid");
            
            cell.messageReminder.text = STRING(model.zone);
            if([cell.messageReminder.text isEqualToString:@"0"])
            {
                cell.messageReminder.hidden = YES;
            }
            else
                cell.messageReminder.hidden = NO;
            break;
        case 1:
            cell.functionLabel.text = @"待使用";
            cell.imgView.image = IMAGE(@"mine_used");
           
            cell.messageReminder.text = STRING(model.one);
            if([cell.messageReminder.text isEqualToString:@"0"])
            {
                cell.messageReminder.hidden = YES;
            }
            else
                 cell.messageReminder.hidden = NO;
            break;
        case 2:
            cell.functionLabel.text = @"待评价";
            cell.imgView.image = IMAGE(@"mine_commend");
            cell.messageReminder.hidden = NO;
            cell.messageReminder.text = STRING(model.five);
            if([cell.messageReminder.text isEqualToString:@"0"])
            {
                cell.messageReminder.hidden = YES;
            }
            else
                 cell.messageReminder.hidden = NO;
            break;
        case 3:
            cell.functionLabel.text = @"退款";
            cell.imgView.image = IMAGE(@"mine_ refund");
            cell.messageReminder.hidden = NO;
            cell.messageReminder.text = STRING(model.six);
            if([cell.messageReminder.text isEqualToString:@"0"])
            {
                cell.messageReminder.hidden = YES;
            }
            else
                 cell.messageReminder.hidden = NO;
            break;
        case 4:
            cell.functionLabel.text = @"全部订单";
            cell.imgView.image = IMAGE(@"mine_all_order");
            cell.messageReminder.hidden = YES;
            break;
        default:
            break;
    }
    return cell;
}

- (UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section{
    
    return UIEdgeInsetsMake(-10, 0, 0, 0);
    
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
    MineCollectionViewCell *cell = (MineCollectionViewCell *)[collectionView cellForItemAtIndexPath:indexPath];
    MineAllOrderViewController *mineVC = [MineAllOrderViewController new];
    mineVC.hidesBottomBarWhenPushed = YES;
    switch (indexPath.row) {
        case 0:
        {
            mineVC.titleName = cell.functionLabel.text;
            mineVC.status = @"0";//待付款
            [self.viewController.navigationController pushViewController:mineVC animated:YES];
        }
            break;
        case 1:
        {

            mineVC.titleName = cell.functionLabel.text;
            mineVC.status = @"1";//待使用
            [self.viewController.navigationController pushViewController:mineVC animated:YES];
        }
            break;
        case 2:
        {

            mineVC.titleName = cell.functionLabel.text;
            mineVC.status = @"5";//待评价
            [self.viewController.navigationController pushViewController:mineVC animated:YES];
        }
            break;
        case 3:
        {

            mineVC.titleName = cell.functionLabel.text;
            mineVC.status = @"6";//退款
            [self.viewController.navigationController pushViewController:mineVC animated:YES];
        }
            break;
        case 4:
        {

            mineVC.titleName = cell.functionLabel.text;
            mineVC.status = @"99";//全部订单
            [self.viewController.navigationController pushViewController:mineVC animated:YES];
        }
            break;
            
        default:
            break;
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
